// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import store from './store/index'
import router from './router'
import iView from 'iview'
import '../src/assets/css/weui.css'
import '../src/assets/css/base.css'
import 'iview/dist/styles/iview.css'
import dictutil from './assets/js/dictutil.js'

Vue.use(iView)
Vue.config.productionTip = false

const ErrorAlert = function(content) {
  iView.Modal.error({
    content: content
  })
}
const SuccessAlert = function(content) {
  iView.Modal.success({
    content: content
  })
}
Vue.prototype.$ErrorAlert = ErrorAlert
Vue.prototype.$SuccessAlert = SuccessAlert

Vue.filter('dict', function(val, key) {
  let tex = dictutil.getText(key, val)
      return tex
})

router.beforeEach((to, from, next) => {
  // var ua = navigator.userAgent.toLowerCase()
  // var isWeixin = ua.indexOf('micromessenger') !== -1
  var isWeixin = true
  if (!isWeixin && to.name !== 'WxError') {
    next({ name: 'WxError' })
  } else if (to.matched.some(m => m.meta.isNotLogin)) {
    document.title = to.meta.title
    next()
  } else {
    // 对登录状态进行验证
    if (store.getters.getLoginState) { // 已经登录
      document.title = to.meta.title
      next()
    } else { // 未登录
      // 未登录,跳转到登陆页面，并且带上 将要去的地址，方便登陆后跳转。
      next({ path: '/faceLogin', query: { toPath: to.fullPath } })
    }
  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  // components: { App },
  // template: '<App/>'
  render: (h) => h(App)
})
